﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataLibrary
{
 public class Ctbl_Quangcao:IData<tbl_Quangcao>
    {
        public Ctbl_Quangcao() { }
        public Ctbl_Quangcao(String myconnecString) :
            base(myconnecString) 
        {
 
        }


        

        public override List<tbl_Quangcao> GetAll(tbl_Quangcao item)
        {
            throw new NotImplementedException();
        }

        public override tbl_Quangcao GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdQuangcao == Convert.ToInt32(id));
        }

        public override tbl_Quangcao GetItem(System.Data.IDataReader dr)
        {
            tbl_Quangcao obj = new tbl_Quangcao();
            obj.IdQuangcao = Convert.ToInt32(dr[tbl_Quangcao.c_idQuangcao]);
            obj.Image = Convert.ToString(dr[tbl_Quangcao.c_Image]);
            obj.IsActive= Convert.ToInt32(dr[tbl_Quangcao.c_isActive]);
            obj.OrderId = Convert.ToInt32(dr[tbl_Quangcao.c_orderId]);
            obj.TitleQuangcao = Convert.ToString(dr[tbl_Quangcao.c_titleQuangcao]);
            obj.UrlQuangcao = Convert.ToString(dr[tbl_Quangcao.c_urlQuangcao]);
            return obj;
        }

        public override List<tbl_Quangcao> GetAll()
        {

            return GetAll("select * from " + tbl_Quangcao.b_tbl_Quangcao + strAsc, CommandType.Text);
        }


        protected override int InsertOnSubmit(tbl_Quangcao item, int t)
        {
            return connec.ExecuteNonQuery("proQuangcao", CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@" + tbl_Quangcao.c_idQuangcao, item.IdQuangcao), new SqlParameter("@" + tbl_Quangcao.c_Image, item.Image),
                new SqlParameter("@" + tbl_Quangcao.c_isActive, item.IsActive), new SqlParameter("@" + tbl_Quangcao.c_orderId, item.OrderId),
                new SqlParameter("@" + tbl_Quangcao.c_titleQuangcao, item.TitleQuangcao), new SqlParameter("@" + tbl_Quangcao.c_urlQuangcao, item.UrlQuangcao));

        }
    }
}
